#ifndef MEDIAMANAGER_H
#define MEDIAMANAGER_H

#include "../Config/Export.h"
#include "../Utilities/Singleton.h"
#include "../Debug/Logger.h"
#include "../Core/ILoader.h"
#include "../Core/Texture.h"
#include "../Core/Model.h"
#include "../Core/Shader.h"
#include "../Debug/Logger.h"
#include "../Debug/Exceptions.h"
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>

namespace epix {

template <class T>
struct MediaHolder
{
    typedef std::map<std::string, ILoader<T>* > TLoadersMap;
    TLoadersMap _loaders;
};

class SHARED MediaManager : public Singleton<MediaManager>,
                            public MediaHolder<Texture>,
                            public MediaHolder<Model>,
                            public MediaHolder<ShaderBase>
{
    MAKE_SINGLETON(MediaManager)

    public:

        template <class T> T *getMedia(const char *filename);
        template <class T> void saveMedia(const T *object, const char *filename);

        template <class T> void registerLoader(ILoader<T> *loader, const std::string &extensions);
        template <class T> void unregisterLoader();

    private:

        template <class T> ILoader<T> *findLoader(const char *filename);
        std::string getExtension(const char *filename) const;

        void split(const std::string &string,
		   std::vector<std::string> &tokens,
		   const std::string delim = " \t\n");
        std::string toLower(const std::string &text);

};

#include "MediaManager.inl"

}

#endif
